package com.sgb.kjwl.view.ui.adapter.pick;


import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.self.PermissionMenuEntity;

import java.util.List;

public class SecondthreeMoreAdapter extends BaseQuickAdapter<PermissionMenuEntity.ListEntity, BaseViewHolder> {
    private boolean isbianji=false;
    private int resID;
    public SecondthreeMoreAdapter(int layoutResId, @Nullable List<PermissionMenuEntity.ListEntity> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, PermissionMenuEntity.ListEntity item) {
        helper.addOnClickListener(R.id.add);
         helper.setText(R.id.moretitle,item.getTitle());
         if (isbianji&&item.getType()==0){
             helper.getView(R.id.add).setVisibility(View.VISIBLE);
         }else {
             helper.getView(R.id.add).setVisibility(View.GONE);
         }
        //获取entity的图标信息
        String icon = item.getIcon();
        if ("4_wodebaojia".equals(item.getName())) {
            icon = "wodebaojia_4";
        }

        if ("dizhiguanli".equals(item.getIcon()) && ("18_dizhiguanli".equals(item.getName()) || "0_dizhiguanli".equals(item.getName()))){
            icon = "dizhiguanli_2";
        }

        if ("0_shangpincuxiao".equals(item.getName()) && "shangpincuxiao".equals(item.getIcon())) {
            icon = "shangpincuxiao_2";
        }

        if ("2_wodebaojia".equals(item.getName())) {
            icon = "wodebaojia_2";
        }

        if ("8_wodebaojia".equals(item.getName())) {
            icon = "wodebaojia_8";
        }

        if ("0_tuanduixinxi".equals(item.getName())) {
            icon = "jibenxinxi";
        }

        if ("7_jingjiafabu".equals(item.getName()) && "jingjiafabu".equals(item.getIcon())) {
            icon = "jingjiafabuwuliu";
        }

        if ("15_zhishichanquan".equals(item.getName())) {
            icon = "zhishichanquan_15";
        }
        if ("5_hanxun".equals(item.getName())){
            icon = "hanxun";
        }
        if ("10_xunjia".equals(item.getName()) || "xunjia".equals(item.getIcon())){
            icon = "xunjia_2";
        }
        if ("12_ucjingjia".equals(item.getName()) || "ucjingjia".equals(item.getIcon())){
            icon = "jingjia_2";
        }
        if ("15_qiyezhuanxiang".equals(item.getName()) || "qiyezhuanxiang1".equals(item.getIcon())){
            icon = "qiyezhuanxiang_2";
        }
        //判断是否存在
        if (!TextUtils.isEmpty(icon)) {
            //获取到对应的本地图标地址id
            resID = mContext.getResources().getIdentifier(icon, "drawable", mContext.getPackageName());
            Log.e("图标名称", icon);
        }
        ImageView img =helper.getView(R.id.img);
        //判断本地图标地址id是否找到
        if (resID != 0) {
            Glide.with(mContext)
                    .load(resID)
                    .apply(new RequestOptions()
                            .error(R.drawable.user_center_def_img)
                            .placeholder(R.drawable.user_center_def_img)
                            .fallback(R.drawable.user_center_def_img))
                    .into(img);
        } else {
            Glide.with(mContext).load(R.drawable.user_center_def_img).into(img);
        }
    }

    public void setisbianji(boolean isbiani){
        this.isbianji =isbiani;
        notifyDataSetChanged();
    }

}
